#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'libb@anchent.com'

import os
import time
from random import randint
from threading import Thread


def download(name):
    print("name:{} download task pid :{}, parent pid:P{}".format(name, os.getpid(), os.getppid()))
    download_time = randint(5, 10)
    time.sleep(download_time)
    print("download task finished cost_time:{}".format(download_time))


if __name__ == '__main__':
    start = time.time()
    print("current python_thread pid is:%d" % os.getpid())
    thread_list = []
    for i in range(10):
        t = Thread(target=download, args=(i,))
        t.start()
        # t.run()
        thread_list.append(t)

    for j in thread_list:
        j.join()

    end = time.time()
    print("total cost_time:%.3f" % (end - start))
